<?php
namespace Amis\dataviewer;

use Amis\Basics\AmisBasics;

class Image extends AmisBasics
{
    /**
     * 如果在 Table、Card 和 List 中，为"image"；在 Form 中用作静态展示，为"static-image"
     */
    public string $type        = 'image';
    public string $type_static = 'static-imag';

    public function className(string $className)
    {
        $this->className = $className;
        return $this;
    }

    public function imageClassName(string $imageClassName)
    {
        $this->imageClassName = $imageClassName;
        return $this;
    }

    public function thumbClassName(string $thumbClassName)
    {
        $this->thumbClassName = $thumbClassName;
        return $this;
    }

    public function height(string $height)
    {
        $this->height = $height;
        return $this;
    }

    public function width(string $width)
    {
        $this->width = $width;
        return $this;
    }

    public function title(string $title)
    {
        $this->title = $title;
        return $this;
    }

    /**
     * 描述
     * @param string $imageCaption
     * @return $this
     */
    public function imageCaption(string $imageCaption)
    {
        $this->imageCaption = $imageCaption;
        return $this;
    }

    /**
     * 占位文本
     * @param string $placeholder
     * @return $this
     */
    public function placeholder(string $placeholder)
    {
        $this->placeholder = $placeholder;
        return $this;
    }

    /**
     * 无数据时显示的图片
     * @param string $defaultImage
     * @return $this
     */
    public function defaultImage(string $defaultImage)
    {
        $this->defaultImage = $defaultImage;
        return $this;
    }

    /**
     * 缩略图地址
     * @param string $src
     * @return $this
     */
    public function src(string $src)
    {
        $this->src = $src;
        return $this;
    }

    /**
     * 外部链接地址
     * @param string $href
     * @return $this
     */
    public function href(string $href)
    {
        $this->href = $href;
        return $this;
    }

    /**
     * 原图地址
     * @param string $href
     * @return $this
     */
    public function originalSrc(string $href)
    {
        $this->originalSrc = $href;
        return $this;
    }

    /**
     * 支持放大预览
     * @param bool $enlargeAble
     * @return $this
     */
    public function enlargeAble(bool $enlargeAble)
    {
        $this->enlargeAble = $enlargeAble;
        return $this;
    }

    /**
     * 放大预览的标题
     * @param string $enlargeTitle
     * @return $this
     */
    public function enlargeTitle(string $enlargeTitle)
    {
        $this->enlargeTitle = $enlargeTitle;
        return $this;
    }

    /**
     * 放大预览的描述
     * @param string $enlargeCaption
     * @return $this
     */
    public function enlargeCaption(string $enlargeCaption)
    {
        $this->enlargeCaption = $enlargeCaption;
        return $this;
    }

    /**
     * 预览图模式，可选：'w-full', 'h-full', 'contain', 'cover'
     * @param string $thumbMode
     * @return $this
     */
    public function thumbMode(string $thumbMode = 'contain')
    {
        if (in_array($thumbMode, ['w-full', 'h-full', 'contain', 'cover'])) {
            $this->thumbMode = $thumbMode;
        }
        return $this;
    }

    /**
     * 预览图比例，可选：'1:1', '4:3', '16:9'
     * @param string $thumbRatio
     * @return $this
     */
    public function thumbRatio(string $thumbRatio = '1:1')
    {
        if (in_array($thumbRatio, ['1:1', '4:3', '16:9'])) {
            $this->thumbRatio = $thumbRatio;
        }
        return $this;
    }

    /**
     * 图片展示模式，可选：'thumb', 'original' 即：缩略图模式 或者 原图模式
     * @param string $imageMode
     * @return $this
     */
    public function imageMode(string $imageMode = 'thumb')
    {
        if (in_array($imageMode, ['thumb', 'original'])) {
            $this->imageMode = $imageMode;
        }
        return $this;
    }
}